function [M2, varargout] = takeLogTransform(M, varargin)
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	% This function takes a matrix as input where each column is a variable, and each
	% column is an observation.
	% It takes a log-transformation of the variables (potentially with some offset C, to take log(x+C).
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Inputs:
	% M:				NumRows x NumCols
	% varargin{1}:		offset --> 1 x 1, or 1 x NumCols, or NumRows x NumCols
	% varargin{2}:		cell(NumCols,1) or strings  (original names of variables)
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	%%%%% Outputs:
	% M2:				NumRows x NumCols
	% varargout{1}:		cell(NumCols,1) or strings  (transformed names of variables)
	%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	% Read dimensions
	[NumRows, NumCols] = size(M);
	
	% Read offsets
	if nargin >= 2
		offsets0 = varargin{1};
		offsets = offsets0;
		if size(offsets, 1) == 1 && size(offsets, 1) == NumCols
			offsets = repmat(offsets, NumRows, 1); % NumRows x NumCols
		end
	else
		offsets0 = 0;
		offsets = 0;
	end
	
	% Take log transform
	M2 = log(M + offsets);
	
	% Get new variable names
	if nargin >= 3
		VarNames2 = varargin{2};
		for cc = 1:NumCols
			if size(offsets0, 1) > 1
				VarNames2{cc} = sprintf('log(%s + offset)', VarNames2{cc});
			else
				if length(offsets0) == 1
					myval = offsets0;
				else
					myval = offsets0(cc);
				end
				if myval == 0
					VarNames2{cc} = sprintf('log(%s)', VarNames2{cc});			
				else
					VarNames2{cc} = sprintf('log(%s + %.1f)', VarNames2{cc}, myval);			
				end
			end
		end
		varargout{1} = VarNames2;
	end
end
